package com.punai.dataanalysis.epdatakb.service.impl;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.function.Function;
import java.util.stream.Collectors;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.StrUtil;
import com.punai.common.core.domain.BaseEntity;
import com.punai.common.utils.DateUtils;
import com.punai.common.utils.NumberUtil;
import com.punai.dataanalysis.epdatakb.bo.JtczResultBo;
import com.punai.dataanalysis.epdatakb.domain.DataAnalysisNdgccbqkhzb;
import com.punai.dataanalysis.epdatakb.service.NG001change1212.NG001CbjxkhC1212Service;
import com.punai.dataanalysis.epdatakb.vo.DataAnalysisVo;
import com.punai.dataanalysis.ng001.bo.YearLjWccz;
import com.punai.dataanalysis.ng001.domain.ProjectTable;
import com.punai.dataanalysis.ng001.mapper.CbjxkhMapper;
import com.punai.dataanalysis.ng001.mapper.ProjectTableMapper;
import com.punai.prodatalibrary.domain.bo.GlobalProInfoBo;
import com.punai.prodatalibrary.service.ILibProjectInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.punai.dataanalysis.epdatakb.mapper.DataAnalysisCbjxkhMapper;
import com.punai.dataanalysis.epdatakb.domain.DataAnalysisCbjxkh;
import com.punai.dataanalysis.epdatakb.service.IDataAnalysisCbjxkhService;

/**
 * 成本绩效考核Service业务层处理
 *
 * @author zxw_
 * @date 2023-04-20
 */
@Service
public class DataAnalysisCbjxkhServiceImpl extends ServiceImpl<DataAnalysisCbjxkhMapper,DataAnalysisCbjxkh> implements IDataAnalysisCbjxkhService
{
    @Autowired
    private DataAnalysisCbjxkhMapper dataAnalysisCbjxkhMapper;


    @Autowired
    private ProjectTableMapper projectTableMapper;

    @Autowired
    private ILibProjectInfoService libProjectInfoService;
    @Autowired
    private CbjxkhMapper cbjxkhMapper;

    @Autowired
    private NG001CbjxkhC1212Service ng001CbjxkhC1212Service;

    @Override
    public List<? extends BaseEntity> getDataList(DataAnalysisVo dataAnalysisVo) {

        if (isC1212) {
            List<? extends BaseEntity> dataList = ng001CbjxkhC1212Service.getDataList(dataAnalysisVo);
            return dataList;
        }


        String tabType = dataAnalysisVo.getTabType();
        String proStatusFilter = null;
        /**
         * 数据来源新中大库
         * select distinct a.Stat, b.descript from  project_table a left join stats b on a.Stat=b.stat
         * project_table.Stat 字段翻译
         * bid	投标项目
         * clo	竣工项目
         * end	工程归档
         * fz	封账项目
         * hit	中标项目
         * JW	竣工未结算
         * JY	竣工已结算
         * pau	停工项目
         * pcl	完工项目
         * stp	终止项目
         * sts	在建项目
         */
        if (StrUtil.equals(tabType,"zjgc")) {
            proStatusFilter = "sts";
        } else  if (StrUtil.equals(tabType,"jggc")){
            proStatusFilter = "clo";
        } else  if (StrUtil.equals(tabType,"jsgc")){
            proStatusFilter = "JY";
        }
        List<GlobalProInfoBo> list = libProjectInfoService.selectInfoListNoPerm(new GlobalProInfoBo());
        List<DataAnalysisCbjxkh> res = new ArrayList<>();
        List<String> pmInfoIds = list.stream().map(GlobalProInfoBo::getPmproinfoid).collect(Collectors.toList());
        List<ProjectTable> projectTables = projectTableMapper.selectCbjxkhListByVo(pmInfoIds,proStatusFilter);
        pmInfoIds = projectTables.stream().map(ProjectTable::getPhid).filter(Objects::nonNull).collect(Collectors.toList());
        if (CollUtil.isEmpty(pmInfoIds)) {
            return new ArrayList<>();
        }
        Map<String, ProjectTable> projectTableMap = projectTables.stream().collect(Collectors.toMap(ProjectTable::getPhid, Function.identity(), (v1, v2) -> v2));

        List<YearLjWccz> qnYs = qnYs(pmInfoIds);
        Map<String, YearLjWccz> qnYsMap = qnYs.stream().collect(Collectors.toMap(YearLjWccz::getPc, Function.identity(), (v1, v2) -> v2));
        List<YearLjWccz> qnCb = qnCb(pmInfoIds);
        Map<String, YearLjWccz> qnCbMap = qnCb.stream().collect(Collectors.toMap(YearLjWccz::getPc, Function.identity(), (v1, v2) -> v2));
        List<YearLjWccz> bnCz = bnCz(pmInfoIds);
        Map<String, YearLjWccz> bnCzMap = bnCz.stream().collect(Collectors.toMap(YearLjWccz::getPc, Function.identity(), (v1, v2) -> v2));
        List<YearLjWccz> bnCb = bnCb(pmInfoIds);
        Map<String, YearLjWccz> bnCbMap = bnCb.stream().collect(Collectors.toMap(YearLjWccz::getPc, Function.identity(), (v1, v2) -> v2));
        List<YearLjWccz> nzCz = nzCz(pmInfoIds);
        Map<String, YearLjWccz> nzCzMap = nzCz.stream().collect(Collectors.toMap(YearLjWccz::getPc, Function.identity(), (v1, v2) -> v2));
        List<YearLjWccz> nzCb = nzCb(pmInfoIds);
        Map<String, YearLjWccz> nzCbMap = nzCb.stream().collect(Collectors.toMap(YearLjWccz::getPc, Function.identity(), (v1, v2) -> v2));


        for (GlobalProInfoBo globalProInfoBo : list) {
            DataAnalysisCbjxkh kh = new DataAnalysisCbjxkh();
            if(StrUtil.isNotEmpty(globalProInfoBo.getPmproinfoid())){
                String pc = globalProInfoBo.getPmproinfoid();
                ProjectTable projectTable = projectTableMap.get(pc);
                if(projectTable == null){
                    continue;
                }
                YearLjWccz qncz = qnYsMap.get(pc);
                YearLjWccz qncb = qnCbMap.get(pc);
                YearLjWccz bncz = bnCzMap.get(pc);
                YearLjWccz bncb = bnCbMap.get(pc);
                YearLjWccz nzcz = nzCzMap.get(pc);
                YearLjWccz nzcb = nzCbMap.get(pc);

                kh = DataAnalysisCbjxkh.conversion(kh,projectTable);
                kh.setQnYsHj(qncz.getPdzhj());
                kh.setQnYsSj(qncz.getSj());
                kh.setQnYsJgc(qncz.getJgc());
                kh.setQnCbHj(qncb.getPdzhj());
                kh.setQnCbJgc(qncb.getJgc());

                kh.setCurrYearCzYs(bncz.getPdzhj());
                kh.setCurrYearCzJgc(bncz.getJgc());
                kh.setCurrYearCzSj(bncz.getSj());
                kh.setCurrYearCb(bncb.getPdzhj());
                kh.setCurrYearCbJgc(bncb.getJgc());

                kh.setNzYsHj(nzcz.getPdzhj());
                kh.setNzYsSj(nzcz.getSj());
                kh.setNzYsJgc(nzcz.getJgc());
                kh.setNzCbHj(nzcb.getPdzhj());
                kh.setNzCbJgc(nzcb.getJgc());

                calcXjZb(kh);
            }
            res.add(kh);
        }

        if (proStatusFilter == null) {
            DataAnalysisCbjxkh jgyjs = ztFz(res, "在建项目");
            DataAnalysisCbjxkh jgwjs = ztFz(res, "竣工未结算");
            DataAnalysisCbjxkh zjxm = ztFz(res, "竣工已结算");
            DataAnalysisCbjxkh zj = zj(res);
            zj.setProName("总合计");
            // 先按专业分组
            res = zyFz(res);
            res.add(jgyjs);
            res.add(jgwjs);
            res.add(zjxm);
            res.add(zj);
        } else if (StrUtil.equals(tabType,"zjgc")) {
            DataAnalysisCbjxkh jgyjs = ztFz(res, "在建项目");
            res.add(jgyjs);
        } else if (StrUtil.equals(tabType,"jggc")){
            DataAnalysisCbjxkh jgwjs = ztFz(res, "竣工未结算");
            res.add(jgwjs);
        } else if (StrUtil.equals(tabType,"jsgc")){
            DataAnalysisCbjxkh zjxm = ztFz(res, "竣工已结算");
            res.add(zjxm);
        }
        return res;
    }

    private List<DataAnalysisCbjxkh> zyFz(List<DataAnalysisCbjxkh> res) {
        List<DataAnalysisCbjxkh> newRes = new ArrayList<>();
        Map<String, List<DataAnalysisCbjxkh>> zyGroup = res.stream().filter(e -> StrUtil.isNotBlank(e.getZy())).collect(Collectors.groupingBy(DataAnalysisCbjxkh::getZy));

        for (Map.Entry<String, List<DataAnalysisCbjxkh>> zyEntry : zyGroup.entrySet()) {
            String zyKey = zyEntry.getKey();
            List<DataAnalysisCbjxkh> zyValue = zyEntry.getValue();
            // 在按项目部分组
            newRes.addAll(zyValue);
            Map<String, List<DataAnalysisCbjxkh>> xmbGroup = zyValue.stream().filter(e -> StrUtil.isNotBlank(e.getProDept())).collect(Collectors.groupingBy(DataAnalysisCbjxkh::getProDept));
            for (Map.Entry<String, List<DataAnalysisCbjxkh>> xmbEntry : xmbGroup.entrySet()) {
                String key = xmbEntry.getKey();
                List<DataAnalysisCbjxkh> value = xmbEntry.getValue();
                DataAnalysisCbjxkh jgyjs = ztFz(res, "在建项目");
                DataAnalysisCbjxkh jgwjs = ztFz(res, "竣工未结算");
                DataAnalysisCbjxkh zjxm = ztFz(res, "竣工已结算");
                newRes.add(jgyjs);
                newRes.add(jgwjs);
                newRes.add(zjxm);
                DataAnalysisCbjxkh zj = zj(value);
                zj.setProName(key + "小计");
                newRes.add(zj);
            }
            DataAnalysisCbjxkh zj = zj(zyValue);
            zj.setProName(zyKey + "小计");
            newRes.add(zj);
        }
        return newRes;
    }


    private DataAnalysisCbjxkh ztFz(List<DataAnalysisCbjxkh> res,String proState ) {
        List<DataAnalysisCbjxkh> vals = res.stream().filter(e -> StrUtil.equals(e.getProStatus(), proState)).collect(Collectors.toList());
        DataAnalysisCbjxkh zj = zj(vals);
        zj.setProName(proState + "小计");
        return zj;
    }

    private DataAnalysisCbjxkh zj(List<DataAnalysisCbjxkh> res) {
        DataAnalysisCbjxkh zj = new DataAnalysisCbjxkh();
        BigDecimal htTotal = BigDecimal.ZERO;
        BigDecimal jzmj = BigDecimal.ZERO;
        BigDecimal sgtYs = BigDecimal.ZERO;
        BigDecimal sgtJgc = BigDecimal.ZERO;
        BigDecimal qnYsHj = BigDecimal.ZERO;
        BigDecimal qnYsSj = BigDecimal.ZERO;
        BigDecimal qnYsJgc = BigDecimal.ZERO;
        BigDecimal qnCbHj = BigDecimal.ZERO;
        BigDecimal qnCbJgc = BigDecimal.ZERO;
        BigDecimal qnLr = BigDecimal.ZERO;
        BigDecimal nzYsHj = BigDecimal.ZERO;
        BigDecimal nzYsSj = BigDecimal.ZERO;
        BigDecimal nzYsJgc = BigDecimal.ZERO;
        BigDecimal nzCbHj = BigDecimal.ZERO;
        BigDecimal nzCbJgc = BigDecimal.ZERO;
        BigDecimal currYearCzYs = BigDecimal.ZERO;
        BigDecimal currYearCzJgc = BigDecimal.ZERO;
        BigDecimal currYearCzSj = BigDecimal.ZERO;
        BigDecimal currYearCzXj = BigDecimal.ZERO;
        BigDecimal currYearCb = BigDecimal.ZERO;
        BigDecimal currYearCbJgc = BigDecimal.ZERO;
        BigDecimal currYearGclr = BigDecimal.ZERO;
        BigDecimal klGclr = BigDecimal.ZERO;
        BigDecimal fzcCbZjPrice = BigDecimal.ZERO;
        for (DataAnalysisCbjxkh re : res) {
            htTotal = NumberUtil.add(htTotal,re.getHtTotal());
            jzmj = NumberUtil.add(jzmj,re.getJzmj());
            sgtYs = NumberUtil.add(sgtYs,re.getSgtYs());
            sgtJgc = NumberUtil.add(sgtJgc,re.getSgtJgc());
            qnYsHj = NumberUtil.add(qnYsHj,re.getQnYsHj());
            qnYsSj = NumberUtil.add(qnYsSj,re.getQnYsSj());
            qnYsJgc = NumberUtil.add(qnYsJgc,re.getQnYsJgc());
            qnCbHj = NumberUtil.add(qnCbHj,re.getQnCbHj());
            qnCbJgc = NumberUtil.add(qnCbJgc,re.getQnCbJgc());
            qnLr = NumberUtil.add(qnLr,re.getQnLr());
            nzYsHj = NumberUtil.add(nzYsHj,re.getNzYsHj());
            nzYsSj = NumberUtil.add(nzYsSj,re.getNzYsSj());
            nzYsJgc = NumberUtil.add(nzYsJgc,re.getNzYsJgc());
            nzCbHj = NumberUtil.add(nzCbHj,re.getNzCbHj());
            nzCbJgc = NumberUtil.add(nzCbJgc,re.getNzCbJgc());
            currYearCzYs = NumberUtil.add(currYearCzYs,re.getCurrYearCzYs());
            currYearCzJgc = NumberUtil.add(currYearCzJgc,re.getCurrYearCzJgc());
            currYearCzSj = NumberUtil.add(currYearCzSj,re.getCurrYearCzSj());
            currYearCzXj = NumberUtil.add(currYearCzXj,re.getCurrYearCzXj());
            currYearCb = NumberUtil.add(currYearCb,re.getCurrYearCb());
            currYearCbJgc = NumberUtil.add(currYearCbJgc,re.getCurrYearCbJgc());
            currYearGclr = NumberUtil.add(currYearGclr,re.getCurrYearGclr());
            klGclr = NumberUtil.add(klGclr,re.getKlGclr());
            fzcCbZjPrice = NumberUtil.add(fzcCbZjPrice,re.getFzcCbZjPrice());
        }

        zj.setHtTotal(htTotal);
        zj.setJzmj(jzmj);
        zj.setSgtYs(sgtYs);
        zj.setSgtJgc(sgtJgc);
        zj.setQnYsHj(qnYsHj);
        zj.setQnYsSj(qnYsSj);
        zj.setQnYsJgc(qnYsJgc);
        zj.setQnCbHj(qnCbHj);
        zj.setQnCbJgc(qnCbJgc);
        zj.setQnLr(qnLr);
        zj.setNzYsHj(nzYsHj);
        zj.setNzYsSj(nzYsSj);
        zj.setNzYsJgc(nzYsJgc);
        zj.setNzCbHj(nzCbHj);
        zj.setNzCbJgc(nzCbJgc);
        zj.setCurrYearCzYs(currYearCzYs);
        zj.setCurrYearCzJgc(currYearCzJgc);
        zj.setCurrYearCzSj(currYearCzSj);
        zj.setCurrYearCzXj(currYearCzXj);
        zj.setCurrYearCb(currYearCb);
        zj.setCurrYearCbJgc(currYearCbJgc);
        zj.setCurrYearGclr(currYearGclr);
        zj.setKlGclr(klGclr);
        zj.setFzcCbZjPrice(fzcCbZjPrice);
        zj.hb();
        calcXjZb(zj);
        return zj;
    }


    private void calcXjZb(DataAnalysisCbjxkh kh) {
        // excel上 未标注算法 和之前的表单一样把
        BigDecimal qnYsHj = kh.getQnYsHj();
        BigDecimal qnYsJgc = kh.getQnYsJgc();
        BigDecimal qnCbHj = kh.getQnCbHj();
        BigDecimal qnLr = NumberUtil.subtract(qnYsHj, qnCbHj);
        kh.setQnLr(qnLr);
        kh.setQnLrl(NumberUtil.divideUseProportion(qnLr,2,NumberUtil.add(qnYsHj,qnYsJgc)));

        // 本年
        BigDecimal currYearCzYs = kh.getCurrYearCzYs();
        BigDecimal currYearCzSj = kh.getCurrYearCzSj();
        BigDecimal currYearCzJgc = kh.getCurrYearCzJgc();
        BigDecimal currYearCb = kh.getCurrYearCb();
        kh.setCurrYearCzXj(NumberUtil.adds(currYearCzYs,currYearCzSj,currYearCzJgc));
        BigDecimal currYearLr = NumberUtil.subtract(currYearCzYs, currYearCb);
        kh.setCurrYearGclr(currYearLr);
        kh.setCurrYearGclrl(NumberUtil.divideUseProportion(currYearLr,2,NumberUtil.add(currYearCzYs,currYearCzJgc)));

        // 累计工程利润
        BigDecimal nzYsHj = kh.getNzYsHj();
        BigDecimal nzYsJgc = kh.getNzYsJgc();
        BigDecimal nzCbHj = kh.getNzCbHj();
        BigDecimal nzLr = NumberUtil.subtract(nzYsHj, nzCbHj);
        kh.setKlGclr(nzLr);
        kh.setKlGclrl(NumberUtil.divideUseProportion(nzLr,2,NumberUtil.add(nzYsHj,nzYsJgc)));
    }

    /**
     * 去年 预算
     * @param pmInfoIds
     * @return
     */
    public List<YearLjWccz> qnYs(List<String> pmInfoIds) {
        List<YearLjWccz> resList = new ArrayList<>();
        List<JtczResultBo> qnYsHj = cbjxkhMapper.qnYsHj(pmInfoIds);
        Map<String, BigDecimal> qnYsHjMap = qnYsHj.stream().collect(Collectors.toMap(JtczResultBo::getText, JtczResultBo::getVal, (v1, v2) -> v2));
        List<JtczResultBo> qnYsSj = cbjxkhMapper.qnYsSj(pmInfoIds);
        Map<String, BigDecimal> qnYsSjMap = qnYsSj.stream().collect(Collectors.toMap(JtczResultBo::getText, JtczResultBo::getVal, (v1, v2) -> v2));
        List<JtczResultBo> qnYsJgc = cbjxkhMapper.qnYsJgc(pmInfoIds);
        Map<String, BigDecimal> qnYsJgcMap = qnYsJgc.stream().collect(Collectors.toMap(JtczResultBo::getText, JtczResultBo::getVal, (v1, v2) -> v2));
        for (String pc : pmInfoIds) {
            YearLjWccz wccz = new YearLjWccz();
            wccz.setPc(pc);
            wccz.setPdzhj(qnYsHjMap.getOrDefault(pc,BigDecimal.ZERO));
            wccz.setSj(qnYsSjMap.getOrDefault(pc,BigDecimal.ZERO));
            wccz.setJgc(qnYsJgcMap.getOrDefault(pc,BigDecimal.ZERO));
            resList.add(wccz);
        }
        return resList;
    }

    /**
     * 去年 成本
     * @param pmInfoIds
     * @return
     */
    public List<YearLjWccz> qnCb(List<String> pmInfoIds) {
        List<YearLjWccz> resList = new ArrayList<>();
        List<JtczResultBo> qnCbHj = cbjxkhMapper.qnCbHj(pmInfoIds);
        Map<String, BigDecimal> qnCbHjMap = qnCbHj.stream().collect(Collectors.toMap(JtczResultBo::getText, JtczResultBo::getVal, (v1, v2) -> v2));
        List<JtczResultBo> qnCbJgc = cbjxkhMapper.qnCbJgc(pmInfoIds);
        Map<String, BigDecimal> qnCbJgcMap = qnCbJgc.stream().collect(Collectors.toMap(JtczResultBo::getText, JtczResultBo::getVal, (v1, v2) -> v2));

        for (String pc : pmInfoIds) {
            YearLjWccz wccz = new YearLjWccz();
            wccz.setPc(pc);
            wccz.setPdzhj(qnCbHjMap.getOrDefault(pc,BigDecimal.ZERO));
            wccz.setJgc(qnCbJgcMap.getOrDefault(pc,BigDecimal.ZERO));
            resList.add(wccz);
        }
        return resList;
    }


    /**
     * 本年 产值
     * @param pmInfoIds
     * @return
     */
    public List<YearLjWccz> bnCz(List<String> pmInfoIds) {
        List<YearLjWccz> resList = new ArrayList<>();
        List<JtczResultBo> bnCzHj = cbjxkhMapper.bnCzHj(pmInfoIds);
        Map<String, BigDecimal> bnCzHjMap = bnCzHj.stream().collect(Collectors.toMap(JtczResultBo::getText, JtczResultBo::getVal, (v1, v2) -> v2));
        List<JtczResultBo> bnCzSj = cbjxkhMapper.bnCzSj(pmInfoIds);
        Map<String, BigDecimal> bnCzSjMap = bnCzSj.stream().collect(Collectors.toMap(JtczResultBo::getText, JtczResultBo::getVal, (v1, v2) -> v2));
        List<JtczResultBo> bnCzJgc = cbjxkhMapper.bnCzJgc(pmInfoIds);
        Map<String, BigDecimal> bnCzJgcMap = bnCzJgc.stream().collect(Collectors.toMap(JtczResultBo::getText, JtczResultBo::getVal, (v1, v2) -> v2));
        for (String pc : pmInfoIds) {
            YearLjWccz wccz = new YearLjWccz();
            wccz.setPc(pc);
            wccz.setPdzhj(bnCzHjMap.getOrDefault(pc,BigDecimal.ZERO));
            wccz.setSj(bnCzSjMap.getOrDefault(pc,BigDecimal.ZERO));
            wccz.setJgc(bnCzJgcMap.getOrDefault(pc,BigDecimal.ZERO));
            resList.add(wccz);
        }

        return resList;
    }


    /**
     * 本年 成本
     * @param pmInfoIds
     * @return
     */
    public List<YearLjWccz> bnCb(List<String> pmInfoIds) {
        List<YearLjWccz> resList = new ArrayList<>();
        List<JtczResultBo> bnCbHj = cbjxkhMapper.bnCbHj(pmInfoIds);
        Map<String, BigDecimal> bnCbHjMap = bnCbHj.stream().collect(Collectors.toMap(JtczResultBo::getText, JtczResultBo::getVal, (v1, v2) -> v2));
        List<JtczResultBo> bnCbJgc = cbjxkhMapper.bnCbJgc(pmInfoIds);
        Map<String, BigDecimal> bnCbJgcMap = bnCbJgc.stream().collect(Collectors.toMap(JtczResultBo::getText, JtczResultBo::getVal, (v1, v2) -> v2));
        for (String pc : pmInfoIds) {
            YearLjWccz wccz = new YearLjWccz();
            wccz.setPc(pc);
            wccz.setPdzhj(bnCbHjMap.getOrDefault(pc,BigDecimal.ZERO));
            wccz.setJgc(bnCbJgcMap.getOrDefault(pc,BigDecimal.ZERO));
            resList.add(wccz);
        }

        return resList;
    }

    /**
     * 年中  5/20 产值
     * @param pmInfoIds
     * @return
     */
    public List<YearLjWccz> nzCz(List<String> pmInfoIds) {
        List<YearLjWccz> resList = new ArrayList<>();
        List<JtczResultBo> nzCzHj = cbjxkhMapper.nzCzHj(pmInfoIds);
        Map<String, BigDecimal> nzCzHjMap = nzCzHj.stream().collect(Collectors.toMap(JtczResultBo::getText, JtczResultBo::getVal, (v1, v2) -> v2));
        List<JtczResultBo> nzCzSj = cbjxkhMapper.nzCzSj(pmInfoIds);
        Map<String, BigDecimal> nzCzSjMap = nzCzSj.stream().collect(Collectors.toMap(JtczResultBo::getText, JtczResultBo::getVal, (v1, v2) -> v2));
        List<JtczResultBo> nzCzJgc = cbjxkhMapper.nzCzJgc(pmInfoIds);
        Map<String, BigDecimal> nzCzJgcMap = nzCzJgc.stream().collect(Collectors.toMap(JtczResultBo::getText, JtczResultBo::getVal, (v1, v2) -> v2));

        for (String pc : pmInfoIds) {
            YearLjWccz wccz = new YearLjWccz();
            wccz.setPc(pc);
            wccz.setPdzhj(nzCzHjMap.getOrDefault(pc,BigDecimal.ZERO));
            wccz.setSj(nzCzSjMap.getOrDefault(pc,BigDecimal.ZERO));
            wccz.setJgc(nzCzJgcMap.getOrDefault(pc,BigDecimal.ZERO));
            resList.add(wccz);
        }
        return resList;
    }


    /**
     * 年中  5/20 成本
     * @param pmInfoIds
     * @return
     */
    public List<YearLjWccz> nzCb(List<String> pmInfoIds) {
        List<YearLjWccz> resList = new ArrayList<>();

        List<JtczResultBo> nzCbHj = cbjxkhMapper.nzCbHj(pmInfoIds);
        Map<String, BigDecimal> nzCbHjMap = nzCbHj.stream().collect(Collectors.toMap(JtczResultBo::getText, JtczResultBo::getVal, (v1, v2) -> v2));
        List<JtczResultBo> nzCbJgc = cbjxkhMapper.nzCbJgc(pmInfoIds);
        Map<String, BigDecimal> nzCbJgcMap = nzCbJgc.stream().collect(Collectors.toMap(JtczResultBo::getText, JtczResultBo::getVal, (v1, v2) -> v2));
        for (String pc : pmInfoIds) {
            YearLjWccz wccz = new YearLjWccz();
            wccz.setPc(pc);
            wccz.setPdzhj(nzCbHjMap.getOrDefault(pc,BigDecimal.ZERO));
            wccz.setJgc(nzCbJgcMap.getOrDefault(pc,BigDecimal.ZERO));
            resList.add(wccz);
        }
        return resList;
    }
}
